package demo
{
	import Box2D.Collision.b2Manifold;
	import Box2D.Dynamics.Contacts.b2Contact;
	import Box2D.Dynamics.b2Body;
	import Box2D.Dynamics.b2ContactImpulse;
	import Box2D.Dynamics.b2ContactListener;
	
	import demo.event.CollideEvent;
	
	import flash.media.Sound;
	
	public class ContactCallback extends b2ContactListener
	{
		public var body:b2Body;
		public var soundPlay:Function;
		public function ContactCallback()
		{
			super();
		}
		override public function EndContact(contact:b2Contact):void{
			super.EndContact(contact);
		}
		override public function BeginContact(contact:b2Contact):void{
			if (contact.GetFixtureA().GetBody() == body){
				soundPlay(contact.GetFixtureB().GetBody());
			} else if (contact.GetFixtureB().GetBody() == body){
				soundPlay(contact.GetFixtureA().GetBody());
			}
			super.BeginContact(contact);
			dispatchEvent(new CollideEvent(CollideEvent.COLLIDE, contact));
		}
		override public function PreSolve(contact:b2Contact, manifold:b2Manifold):void{
			super.PreSolve(contact, manifold);
		}
		override public function PostSolve(contact:b2Contact, contactImp:b2ContactImpulse):void{
			super.PostSolve(contact, contactImp);
		}
	}
}